<?php
require_once("../data/common.php");
if ($user->logged_in == FALSE) {
	die("Login first.");
}
$sql = "SELECT
								tr.device_id AS device_id,
								tr.track_id AS track_id,
								tr.privacy AS privacy,
								u.username AS username
				FROM
								users u,
								tracks tr,
								users_devices ud
				WHERE
								(tr.device_id=ud.id AND
								ud.user_id=u.id) AND
								u.id = ? AND
								tr.track_id = ?
				ORDER BY tr.created DESC;";
$stmt = $dbh->prepare($sql);
$stmt->execute(array($user->logged_in_user_id, $_GET['track']));
$rows = $stmt->fetchAll();
if (count($rows) == 1) {
	$sql = "UPDATE tracks SET
								privacy = ?
				WHERE
								track_id = ? ;";
	$stmt = $dbh->prepare($sql);
	if ($_GET["vis"] == 1) {
		$privacy = 0;
	} else {
		$privacy = 1;
	}
	$stmt->execute(array($privacy, $rows[0]['track_id']));
}
?>